package com.inews.business.wangpan.sina;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.multipart.FilePart;
import org.apache.commons.httpclient.methods.multipart.MultipartRequestEntity;
import org.apache.commons.httpclient.methods.multipart.Part;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import com.kanbox.api.Kanbox;
import com.kanbox.api.Token;

public class KanboxPan {

	//private static String code="86774610f3ed7ce1fb4e4d38b3c25b31";
	private static String client_id="f9c0a1f7a42d1ffd4e6c155220116760";
	private static String client_secret="fe8c8a0332affa84beefa8815b7acc39";
	private static String frefresh_token="e090290621b0b8655c7e5618891403f5";
	

	public static void main(String[] args) throws Exception{
		Token token=new Token();
		token.refreshToken(client_id, client_secret, frefresh_token);
		System.out.println(token.getAcceccToken());
		System.out.println(Kanbox.getInstance().getFileList(token, "/test"));
		System.out.println(Kanbox.getInstance().upload(new File("D://a.txt"), "/test/c.txt", token));
		
	}
	
	public static String info() throws Exception{
		Token token=new Token();
		token.refreshToken(client_id, client_secret, frefresh_token);
		return Kanbox.getInstance().getFileList(token, "/test");
	}

	
	public static InputStream download(String fileName) throws Exception{
		Token token=new Token();
		token.refreshToken(client_id, client_secret, frefresh_token);
		return	Kanbox.getInstance().download( fileName, token);
	}

	public static  String UploadFile(File temp, String originalFilename) throws Exception {
		// TODO Auto-generated method stub
		Token token=new Token();
		token.refreshToken(client_id, client_secret, frefresh_token);
		return Kanbox.getInstance().upload(temp, originalFilename, token);
		
	}
	
	public static  String deleteFile(String path) throws Exception {
		// TODO Auto-generated method stub
		Token token=new Token();
		token.refreshToken(client_id, client_secret, frefresh_token);
		return Kanbox.getInstance().deleteFile(token, path);
		
	}

}
